package com.nuist.springmvcdemo.ds;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;

public class Set_test {
    public static void main(String[] args) {
        Set<String> s = new TreeSet<>();

        // add() 如果key不存在, 则插入, 返回True
        // 否则返回false
        boolean isln = s.add("apple");
        System.out.println(isln);
        s.add("orange");
        s.add("banana");
        s.add("peach");
        System.out.println(s.size());
        System.out.println(s);

        isln = s.add("apple");
        System.out.println(isln);

        // contains
        System.out.println(s.contains("apple"));
        System.out.println(s.contains("watermelon"));

        // 迭代器
        Iterator<String> iterator = s.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next() + " ");
        }
    }
}
